package com.ruoyi.web.controller.student;

import com.github.pagehelper.PageInfo;
import com.ruoyi.system.domain.Result;
import com.ruoyi.system.domain.Student;
import com.ruoyi.system.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    /**
     * 增
     */
    @PostMapping("inseart")
    public Result inseart(@RequestBody Student student){
        Result result = new Result();
        Integer res = studentService.inseart(student);
        if(res == 1){
            result.setState(1);
            result.setMessage("添加成功");
        }else{
            result.setState(0);
            result.setMessage("添加失败");
        }
        return result;
    }
    /**
     *删
     */
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id")Integer id){
        Result result = new Result();
        Integer res = studentService.delete(id);
        if(res == 1){
            result.setState(1);
            result.setMessage("删除成功");
        }else{
            result.setState(0);
            result.setMessage("删除失败");
        }
        return result;

    }
    /**
     * 改
     */
    @PostMapping("update")
    public Result update(@RequestBody Student student){
        Result result = new Result();
        Integer res = studentService.update(student);
        if(res == 1){
            result.setState(1);
            result.setMessage("更新成功");
        }else{
            result.setState(0);
            result.setMessage("更新失败");
        }
        return result;
    }
    /**
     * 查
     */
    @GetMapping("find/{pageNum}/{pageSize}")
    public Result find(@PathVariable("pageNum")Integer pageNum,@PathVariable("pageSize")Integer pageSize){
        Result result = new Result();
        PageInfo pageInfo = studentService.find(pageNum,pageSize);
        result.setState(1);
        result.setMessage("获取成功");
        result.setData(pageInfo);
        return result;
    }
}
